//
//  MeViewController.m
//  BigJoy
//
//  Created by new-1020 on 2017/6/12.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "MeViewController.h"
//#import "MeHeaderView.h"
#import "XMnavigationController.h"
#import "LoginViewController.h"
#import "NewMeheadView.h"
#import "DesignerListViewController.h"
#import "CategoryListViewController.h"
#import "MyWalletViewController.h"
#import "MeTableCell.h"
#import "AuthenticationDesignerVC.h"
#import "SettingViewController.h"
#import "ShopCarVC.h"
#import "WaiteDIspathVC.h"
#import "AftermarketVC.h"
#import "MyOrderVC.h"
#import "InviteVC.h"
#import "ErWeiMaView.h"

@interface MeViewController ()
@property (nonatomic,strong) NSArray * nameArray;
@property (nonatomic,strong) NSArray * imageArray;
@end

@implementation MeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self dataInit];
    [self setUI];
    
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

-(void)dataInit{
    self.nameArray = @[@[@"我的收藏",@"",@""],
                       @[@"我的钱包",@"玩设计、晒产品、赚金钱",@""],
                       @[@"设计师认证",@"认证专享专区福利",@"未认证"],
                       @[@"推荐有礼",@"邀请好友来拿钱",@""],
                       @[@"帮助中心",@"",@""],
                       @[@"系统设置",@"",@""],
                       @[@"关于我们",@"",@""]];
}

-(void)setUI {
    [self.view addSubview:self.XMTableview];
    self.leftButton = [[UIButton alloc]init];
    [self.leftButton setImage:[UIImage imageNamed:@"qr_code"] forState:UIControlStateNormal];
    self.rightButton = [[UIButton alloc]init];
    [self.rightButton setImage:[UIImage imageNamed:@"message_light"] forState:UIControlStateNormal];
    [self.rightButton sizeToFit];
    [self.leftButton sizeToFit];
    @weakify(self);
    [[self.leftButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self showTheEwmView];
    }];
    self.hideNavLine = YES;
    self.XMTableview.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49 - 64);
    self.XMTableview.backgroundColor = [UIColor whiteColor];
    //addHeader
    NewMeheadView * headerView = [NewMeheadView fastLogin];
    if ([UserTool isLogin]) {
        headerView.model = [UserTool getTheUserModel];
    }
    //监听各个按钮的点击
    [headerView setBtnClickBlock:^(NSInteger tag){
        @strongify(self);
        if (tag == 0) {
            //关注
            DesignerListViewController * vc = [DesignerListViewController new];
            vc.jumpType = MYSTAR;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 1) {
            //粉丝
            DesignerListViewController * vc = [DesignerListViewController new];
            vc.jumpType = MYFANS;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 2) {
            //保存
            CategoryListViewController * vc = [CategoryListViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 3) {
            //发布
        }
        if (tag == 4) {
            //社区
        }
        if (tag == 5) {
            //购物车
            ShopCarVC * vc = [ShopCarVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 6) {
            //待付款
            WaiteDIspathVC * vc = [WaiteDIspathVC new];
            vc.cellType = WaitePay;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 7) {
            //待发货
            WaiteDIspathVC * vc = [WaiteDIspathVC new];
            vc.cellType = WaiteDispath;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 8) {
            //待收huo
            WaiteDIspathVC * vc = [WaiteDIspathVC new];
            vc.cellType = WaiteReceive;
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 9) {
            //售后
            AftermarketVC * vc = [AftermarketVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (tag == 10) {
            //我的订单
            MyOrderVC * vc = [MyOrderVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }];
    headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 330);
    self.XMTableview.tableHeaderView = headerView;
}
#pragma -mark:二维码
-(void)showTheEwmView {
    NSString * idstr = @"1993";
    UIImage * image = [XMSuperHelper erWeiMaWithStr:idstr];
    ErWeiMaView * view = [ErWeiMaView fastLogin];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH,SCREEN_HEIGHT);
    view.imageView.image = image;
    [XMKEYWINDOWXM addSubview:view];
}


//talbelViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.nameArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MeTableCell * cell = [MeTableCell cellWithTalbelView:tableView];
    cell.titleLabel.text = self.nameArray[indexPath.row][0];
    cell.subTitleLbale.text = self.nameArray[indexPath.row][1];
    cell.traningLable.text = self.nameArray[indexPath.row][2];
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            // 我的收藏
            CategoryListViewController * vc = [[CategoryListViewController alloc]init];
            vc.title = @"我的收藏";
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 1) {
            // 我的钱包
            MyWalletViewController * vc = [[MyWalletViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 2) {
            // 设计师认证
            AuthenticationDesignerVC * vc = [AuthenticationDesignerVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 3) {
            // 推荐有礼
            InviteVC * vc = [InviteVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 4) {
            // 帮助中心
        }
        if (indexPath.row == 5) {
            // 系统设置
            SettingViewController * vc = [SettingViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if (indexPath.row == 6) {
            //关于我们
        }
        
    }
}



@end
